package org.nidy.erp.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static final String SecretKey = "grace-ok";
    private static final long ExpirationTime = 2*60*60*1000;
    public static String generateToken(Map<String,Object> claims){
       return Jwts.builder().signWith(SignatureAlgorithm.HS256,SecretKey)
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+ExpirationTime))
                .compact();
    }
    public static Claims parseToken(String token) throws Exception{
        return Jwts.parser()
                .setSigningKey(SecretKey)
                .parseClaimsJws(token)
                .getBody();
    }
}
